function U = payoffs(theta,X,Z,YY,reb,mpow)

N=size(X,1);
KZ=size(Z,2)/5;
% NS=size(V_R,2);
nBetaR = length(reb{1});
nBetaI1 = length(mpow{1});
nBetaI2 = length(mpow{2});
nPhi1 = length(reb{2});
nPhi2 = length(reb{3});
nGamma1 = length(mpow{3});
nGamma2 = length(mpow{4});
nYY=size(YY,1);

Xrebel = X(:,reb{1});
Xmpow1 = X(:,mpow{1});
Xmpow2 = X(:,mpow{2});

ZUS = Z(:,1:KZ);
ZUK = Z(:,KZ+(1:KZ)); 
ZFRN = Z(:,2*KZ+(1:KZ));
ZRUS = Z(:,3*KZ+(1:KZ));
ZCHN = Z(:,4*KZ+(1:KZ));

ZrebelUS1 = ZUS(:,reb{2}); ZrebelUS2 = ZUS(:,reb{3});
ZrebelUK1 = ZUK(:,reb{2}); ZrebelUK2 = ZUK(:,reb{3});
ZrebelFRN1 = ZFRN(:,reb{2}); ZrebelFRN2 = ZFRN(:,reb{3});
ZrebelRUS1 = ZRUS(:,reb{2}); ZrebelRUS2 = ZRUS(:,reb{3});
ZrebelCHN1 = ZCHN(:,reb{2}); ZrebelCHN2 = ZCHN(:,reb{3});
ZmpowUS1 = ZUS(:,mpow{3}); ZmpowUS2 = ZUS(:,mpow{4});
ZmpowUK1 = ZUK(:,mpow{3}); ZmpowUK2 = ZUK(:,mpow{4});
ZmpowFRN1 = ZFRN(:,mpow{3}); ZmpowFRN2 = ZFRN(:,mpow{4});
ZmpowRUS1 = ZRUS(:,mpow{3}); ZmpowRUS2 = ZRUS(:,mpow{4});
ZmpowCHN1 = ZCHN(:,mpow{3}); ZmpowCHN2 = ZCHN(:,mpow{4});

beta_R=theta(1:nBetaR,1);

beta_US1=theta(nBetaR+[1,5+(1:nBetaI1-1)],1);
beta_UK1=theta(nBetaR+[2,5+(1:nBetaI1-1)],1);
beta_FRN1=theta(nBetaR+[3,5+(1:nBetaI1-1)],1);
beta_RUS1=theta(nBetaR+[4,5+(1:nBetaI1-1)],1);
beta_CHN1=theta(nBetaR+[5,5+(1:nBetaI1-1)],1);
beta_US2=theta(nBetaR+4+nBetaI1+[1,5+(1:nBetaI2-1)],1);
beta_UK2=theta(nBetaR+4+nBetaI1+[2,5+(1:nBetaI2-1)],1);
beta_FRN2=theta(nBetaR+4+nBetaI1+[3,5+(1:nBetaI2-1)],1);
beta_RUS2=theta(nBetaR+4+nBetaI1+[4,5+(1:nBetaI2-1)],1);
beta_CHN2=theta(nBetaR+4+nBetaI1+[5,5+(1:nBetaI2-1)],1);
    
phi_US1=theta(nBetaR+4+nBetaI1+4+nBetaI2+1,1);
phi_UK1=theta(nBetaR+4+nBetaI1+4+nBetaI2+2,1);
phi_FRN1=theta(nBetaR+4+nBetaI1+4+nBetaI2+3,1);
phi_RUS1=theta(nBetaR+4+nBetaI1+4+nBetaI2+4,1);
phi_CHN1=theta(nBetaR+4+nBetaI1+4+nBetaI2+5,1);
phi_R1=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+(1:nPhi1),1);
phi_US2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+1,1);
phi_UK2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+2,1);
phi_FRN2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+3,1);
phi_RUS2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+4,1);
phi_CHN2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5,1);
phi_R2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+(1:nPhi2),1);

gamma1=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+(1:nGamma1),1);
gamma2=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+(1:nGamma2),1);

deltaS_US_UK=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+1,1);
deltaS_US_FRN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+2,1);
deltaS_US_RUS=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+3,1);
deltaS_US_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+4,1);
deltaS_UK_FRN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+5,1);
deltaS_UK_RUS=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+6,1);
deltaS_UK_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+7,1);
deltaS_FRN_RUS=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+8,1);
deltaS_FRN_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+9,1);
deltaS_RUS_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10,1);
deltaO_US_UK=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+1,1);
deltaO_US_FRN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+2,1);
deltaO_US_RUS=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+3,1);
deltaO_US_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+4,1);
deltaO_UK_FRN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+5,1);
deltaO_UK_RUS=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+6,1);
deltaO_UK_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+7,1);
deltaO_FRN_RUS=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+8,1);
deltaO_FRN_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+9,1);
deltaO_RUS_CHN=theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+10+10,1);

% lambda = theta(nBetaR+4+nBetaI1+4+nBetaI2+5+nPhi1+5+nPhi2+nGamma1+nGamma2+21:end,1);

U = zeros(nYY,6,N);

for n=1:N
    
    U(:,1,n) = YY(:,1) .* (Xrebel(n,:)*beta_R + ...
        (YY(:,2)==1)*(phi_US1+ZrebelUS1(n,:)*phi_R1) + ...
        (YY(:,2)==2)*(phi_US2+ZrebelUS2(n,:)*phi_R2) + ...
        (YY(:,3)==1)*(phi_UK1+ZrebelUK1(n,:)*phi_R1) + ...
        (YY(:,3)==2)*(phi_UK2+ZrebelUK2(n,:)*phi_R2) + ...
        (YY(:,4)==1)*(phi_FRN1+ZrebelFRN1(n,:)*phi_R1) + ...
        (YY(:,4)==2)*(phi_FRN2+ZrebelFRN2(n,:)*phi_R2) + ...
        (YY(:,5)==1)*(phi_RUS1+ZrebelRUS1(n,:)*phi_R1) + ...
        (YY(:,5)==2)*(phi_RUS2+ZrebelRUS2(n,:)*phi_R2) + ...
        (YY(:,6)==1)*(phi_CHN1+ZrebelCHN1(n,:)*phi_R1) + ...
        (YY(:,6)==2)*(phi_CHN2+ZrebelCHN2(n,:)*phi_R2));
    
    U(:,2,n) = (YY(:,2)==1) .* (Xmpow1(n,:)*beta_US1 + ZmpowUS1(n,:)*gamma1 + ...
        (YY(:,3)==1)*deltaS_US_UK + (YY(:,3)==2)*deltaO_US_UK + ...
        (YY(:,4)==1)*deltaS_US_FRN + (YY(:,4)==2)*deltaO_US_FRN + ...
        (YY(:,5)==1)*deltaS_US_RUS + (YY(:,5)==2)*deltaO_US_RUS + ...
        (YY(:,6)==1)*deltaS_US_CHN + (YY(:,6)==2)*deltaO_US_CHN) + ...
        (YY(:,2)==2) .* (Xmpow2(n,:)*beta_US2 + ZmpowUS2(n,:)*gamma2 + ...
        (YY(:,3)==1)*deltaO_US_UK + (YY(:,3)==2)*deltaS_US_UK + ...
        (YY(:,4)==1)*deltaO_US_FRN + (YY(:,4)==2)*deltaS_US_FRN + ...
        (YY(:,5)==1)*deltaO_US_RUS + (YY(:,5)==2)*deltaS_US_RUS + ...
        (YY(:,6)==1)*deltaO_US_CHN + (YY(:,6)==2)*deltaS_US_CHN);
    
    U(:,3,n) = (YY(:,3)==1) .* (Xmpow1(n,:)*beta_UK1 + ZmpowUK1(n,:)*gamma1 + ...
        (YY(:,2)==1)*deltaS_US_UK + (YY(:,2)==2)*deltaO_US_UK + ...
        (YY(:,4)==1)*deltaS_UK_FRN + (YY(:,4)==2)*deltaO_UK_FRN + ...
        (YY(:,5)==1)*deltaS_UK_RUS + (YY(:,5)==2)*deltaO_UK_RUS + ...
        (YY(:,6)==1)*deltaS_UK_CHN + (YY(:,6)==2)*deltaO_UK_CHN) + ...
        (YY(:,3)==2) .* (Xmpow2(n,:)*beta_UK2 + ZmpowUK2(n,:)*gamma2 + ...
        (YY(:,2)==1)*deltaO_US_UK + (YY(:,2)==2)*deltaS_US_UK + ...
        (YY(:,4)==1)*deltaO_UK_FRN + (YY(:,4)==2)*deltaS_UK_FRN + ...
        (YY(:,5)==1)*deltaO_UK_RUS + (YY(:,5)==2)*deltaS_UK_RUS + ...
        (YY(:,6)==1)*deltaO_UK_CHN + (YY(:,6)==2)*deltaS_UK_CHN);

    U(:,4,n) = (YY(:,4)==1) .* (Xmpow1(n,:)*beta_FRN1 + ZmpowFRN1(n,:)*gamma1 + ...
        (YY(:,2)==1)*deltaS_US_FRN + (YY(:,2)==2)*deltaO_US_FRN + ...
        (YY(:,3)==1)*deltaS_UK_FRN + (YY(:,3)==2)*deltaO_UK_FRN + ...
        (YY(:,5)==1)*deltaS_FRN_RUS + (YY(:,5)==2)*deltaO_FRN_RUS + ...
        (YY(:,6)==1)*deltaS_FRN_CHN + (YY(:,6)==2)*deltaO_FRN_CHN) + ...
        (YY(:,4)==2) .* (Xmpow2(n,:)*beta_FRN2 + ZmpowFRN2(n,:)*gamma2 + ...
        (YY(:,2)==1)*deltaO_US_FRN + (YY(:,2)==2)*deltaS_US_FRN + ...
        (YY(:,3)==1)*deltaO_UK_FRN + (YY(:,3)==2)*deltaS_UK_FRN + ...
        (YY(:,5)==1)*deltaO_FRN_RUS + (YY(:,5)==2)*deltaS_FRN_RUS + ...
        (YY(:,6)==1)*deltaO_FRN_CHN + (YY(:,6)==2)*deltaS_FRN_CHN);
    
    U(:,5,n) = (YY(:,5)==1) .* (Xmpow1(n,:)*beta_RUS1 + ZmpowRUS1(n,:)*gamma1 + ...
        (YY(:,2)==1)*deltaS_US_RUS + (YY(:,2)==2)*deltaO_US_RUS + ...
        (YY(:,3)==1)*deltaS_UK_RUS + (YY(:,3)==2)*deltaO_UK_RUS + ...
        (YY(:,4)==1)*deltaS_FRN_RUS + (YY(:,4)==2)*deltaO_FRN_RUS + ...
        (YY(:,6)==1)*deltaS_RUS_CHN + (YY(:,6)==2)*deltaO_RUS_CHN) + ...
        (YY(:,5)==2) .* (Xmpow2(n,:)*beta_RUS2 + ZmpowRUS2(n,:)*gamma2 + ...
        (YY(:,2)==1)*deltaO_US_RUS + (YY(:,2)==2)*deltaS_US_RUS + ...
        (YY(:,3)==1)*deltaO_UK_RUS + (YY(:,3)==2)*deltaS_UK_RUS + ...
        (YY(:,4)==1)*deltaO_FRN_RUS + (YY(:,4)==2)*deltaS_FRN_RUS + ...
        (YY(:,6)==1)*deltaO_RUS_CHN + (YY(:,6)==2)*deltaS_RUS_CHN);

    U(:,6,n) = (YY(:,6)==1) .* (Xmpow1(n,:)*beta_CHN1 + ZmpowCHN1(n,:)*gamma1 + ...
        (YY(:,2)==1)*deltaS_US_CHN + (YY(:,2)==2)*deltaO_US_CHN + ...
        (YY(:,3)==1)*deltaS_UK_CHN + (YY(:,3)==2)*deltaO_UK_CHN + ...
        (YY(:,4)==1)*deltaS_FRN_CHN + (YY(:,4)==2)*deltaO_FRN_CHN + ...
        (YY(:,5)==1)*deltaS_RUS_CHN + (YY(:,5)==2)*deltaO_RUS_CHN) + ...
        (YY(:,6)==2) .* (Xmpow2(n,:)*beta_CHN2 + ZmpowCHN2(n,:)*gamma2 + ...
        (YY(:,2)==1)*deltaO_US_CHN + (YY(:,2)==2)*deltaS_US_CHN + ...
        (YY(:,3)==1)*deltaO_UK_CHN + (YY(:,3)==2)*deltaS_UK_CHN + ...
        (YY(:,4)==1)*deltaO_FRN_CHN + (YY(:,4)==2)*deltaS_FRN_CHN + ...
        (YY(:,5)==1)*deltaO_RUS_CHN + (YY(:,5)==2)*deltaS_RUS_CHN);

end

